#!/usr/bin/python

from datetime import date
YEARS = str(date.today().year)
COPYRIGHT_HOLDER = "Jasm Sison"
APP = "openhaxechart"

GPL_NOTICE = "/**\n\
      This file is part of %s.\n    \n\
      %s is free software: you can redistribute it and/or modify\n\
      it under the terms of the GNU General Public License as published by\n\
      the Free Software Foundation, either version 3 of the License, or\n\
      (at your option) any later version.\n    \n\
      %s is distributed in the hope that it will be useful,\n\
      but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
      GNU General Public License for more details.\n    \n\
      You should have received a copy of the GNU General Public License\n\
      along with %s.  If not, see <http://www.gnu.org/licenses/>.\n    \n\
      Copyright %s %s \n\
*/\n\n" % (APP,APP,APP,APP,COPYRIGHT_HOLDER,YEARS)

def backup_files(file_list):
  ## create backup of files with orig suffix, borken!!
  from shutil import copy2
  for filename in file_list:
    copy2(filename, filename  + ".orig")

def prefix_gpl_notice(file_list):
  ## create new files with GPL notice
  for filename in file_list:
    src_file = open(filename + ".orig", 'r')
    dst_file = open(filename, 'w')
    lines = src_file.readlines()
    lines.reverse()
    lines.append(GPL_NOTICE)
    lines.reverse()
    dst_file.writelines(lines)
    src_file.close()
    dst_file.close()

def main(av):
  backup_files(av)
  prefix_gpl_notice(av)

if __name__ == '__main__':
  import sys
  main(sys.argv[1:])
